package com.nathan.crm.controller;

import com.nathan.base.BaseController;
import com.nathan.base.ResultInfo;
import com.nathan.crm.enums.StateStatus;
import com.nathan.crm.query.CusDevPlanQuery;
import com.nathan.crm.query.SaleChanceQuery;
import com.nathan.crm.service.CusDevPlanService;
import com.nathan.crm.service.SaleChanceService;
import com.nathan.crm.utils.LoginUserUtil;
import com.nathan.crm.vo.CusDevPlan;
import com.nathan.crm.vo.SaleChance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("cus_dev_plan")
public class CusDevPlanController extends BaseController {

    @Autowired
    private SaleChanceService saleChanceService;

    @Autowired
    private CusDevPlanService cusDevPlanService;

    /*
        分页查询客户开发计划数据
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryCusDevPlanByParams(CusDevPlanQuery cusDevPlanQuery){
        return cusDevPlanService.queryCusDevPlanByParams(cusDevPlanQuery);
    }

    /*
        添加客户开发计划
     */
    @RequestMapping("add")
    @ResponseBody
    public ResultInfo addCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.addCusDevPlan(cusDevPlan);

        return success("添加成功！");
    }

    /*
        更新客户开发计划
     */
    @RequestMapping("update")
    @ResponseBody
    public ResultInfo updateCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.updateCusDevPlan(cusDevPlan);

        return success("更新成功！");
    }

    /*
        根据id删除客户开发计划数据
     */
    @RequestMapping("delete")
    @ResponseBody
    public ResultInfo deleteCusDevPlan(Integer id){
        cusDevPlanService.deleteById(id);
        return success("删除成功");
    }

    /*
        跳转到客户开发计划页面
     */
    @RequestMapping("index")
    public String index(){
        return "cusDevPlan/cus_dev_plan";
    }

    /*
        跳转到计划项开发与详情页面
     */
    @RequestMapping("toCusDevPlanDataPage")
    public String toCusDevPlanDataPage(Integer sid, HttpServletRequest request){

        //根据id查询对应的营销计划数据
        SaleChance saleChance = saleChanceService.selectByPrimaryKey(sid);

        //将数据存入到request域对象中
        request.setAttribute("saleChance",saleChance);

        return "cusDevPlan/cus_dev_plan_data";
    }

    /*
        跳转到添加或修改客户开发计划页面
     */
    @RequestMapping("addOrUpdateCusDevPlanPage")
    public String addOrUpdateCusDevPlanPage(Integer sid,Integer id, Model model){
        //传入了客户开发计划id，表示进行更新操作
        if (id != null){
            //根据id查询对应的数据
            CusDevPlan cusDevPlan = cusDevPlanService.selectByPrimaryKey(id);
            model.addAttribute("cusDevPlan",cusDevPlan);
        }

        //获取营销机会id添加到域对象中传给add_update页面
        model.addAttribute("sid",sid);
        return "cusDevPlan/add_update";
    }

}
